package model.elements;

import model.collisions.CollisionCategory;
import model.elements.ArtificialIntelligence.ArtificialIntelligence;
import model.elements.attributes.Coordinate2D;
import model.elements.attributes.Damage;
import model.elements.behaviours.DoesDamage;
import model.elements.configurations.NonPlayerCharacterConfig;
import model.elements.states.weapon.ElementWeaponState;
import model.exceptions.CommandFactoryIsNotReady;
import model.exceptions.ModelExceptions;

// TODO: Auto-generated Javadoc
/**
 * The Class NonPlayerCharacter.
 */
public class NonPlayerCharacter extends Character implements DoesDamage
{
	
	/** The m_ ia. */
	ArtificialIntelligence 	m_IA;
	
	/** The m_damage. */
	Damage					m_damage;
	
	/**
	 * Instantiates a new non player character.
	 *
	 * @param startingPosition the starting position
	 * @param config the config
	 * @throws ModelExceptions the model exceptions
	 */
	public NonPlayerCharacter( Coordinate2D startingPosition, NonPlayerCharacterConfig config ) throws ModelExceptions
	{
		super(startingPosition);
		m_lives 			= config.getLives();
		m_speed 			= config.getSpeed();
		m_equippedWeapon	= config.getWeapon();
		m_IA				= config.getNonPlayerCharacterIA();
		m_damage			= config.getDamage();
		m_lifeState.setCategory( config.getCollisionCategory() );
		m_lifeState.setCommand( m_IA.getCommand(this) );
	}
	
	/**
	 * * Indexable Interface **.
	 *
	 * @throws ModelExceptions the model exceptions
	 */
	
	/*
	 // DEPRECATED
	
	@Override
	public boolean isNonPlayerCharacter()
	{
		return true;
	}
    */
	
	/*** DoesDamage Interface 
	 * @throws ModelExceptions ***/
	
	@Override
	public void update() throws ModelExceptions
	{
		m_lifeState.getCommand().execute( this );
		m_lifeState.setCommand( m_IA.getCommand(this) );	
	}
	
	/* (non-Javadoc)
	 * @see model.elements.behaviours.DoesDamage#doDamage()
	 */
	@Override
	public Damage doDamage() 
	{
		return m_damage;
	}

	/* (non-Javadoc)
	 * @see model.elements.Character#getCollisionCategory()
	 */
	@Override
	public CollisionCategory getCollisionCategory() 
	{
		return m_lifeState.getCategory();
	}

	/* (non-Javadoc)
	 * @see model.elements.Character#onDeath()
	 */
	@Override
	public void onDeath() throws CommandFactoryIsNotReady, ModelExceptions 
	{
		// TODO dropear random upgrade
		
	}
	
	/**
	 * Sets the weapon state.
	 *
	 * @param weapon the new weapon state
	 */
	protected void setWeaponState(ElementWeaponState weapon)
	{
		m_equippedWeapon = weapon;
	}
	
	/* (non-Javadoc)
	 * @see model.elements.behaviours.UsesWeapon#setWeapon(model.elements.states.weapon.ElementWeaponState)
	 */
	@Override
	public void setWeapon(ElementWeaponState weapon) throws ModelExceptions
	{
	}

}
